package com.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 王霄
 * @date 2022/1/8 13:07
 */
@Configuration
public class DirectConfig {

    public static final String EXCHANGE_NAME = "direct.exchange";
    public static final String QUEUE1 = "direct.queue1";
    public static final String QUEUE2 = "direct.queue2";

    @Bean(EXCHANGE_NAME)
    public DirectExchange directExchange() {
        return new DirectExchange(EXCHANGE_NAME);
    }

    @Bean(QUEUE1)
    public Queue queue1() {
        return new Queue(QUEUE1);
    }

    @Bean(QUEUE2)
    public Queue queue2() {
        return new Queue(QUEUE2);
    }

    @Bean
    public Binding directBindingOrange() {
        return BindingBuilder
                .bind(queue1())
                .to(directExchange())
                .with("orange");
    }

    @Bean
    public Binding directBindingBlack() {
        return BindingBuilder
                .bind(queue2())
                .to(directExchange())
                .with("black");
    }

    @Bean
    public Binding directBindingGreen() {
        return BindingBuilder
                .bind(queue2())
                .to(directExchange())
                .with("green");
    }

}
